<template>
	<div>
    <div style="width: 100%">
      <el-button style="float: right;margin-right: 10px" @click="add">添加捐赠人</el-button>
    </div>
		<el-table
			:data="tableData"
			width="100%"

			>
			<el-table-column
			  prop="name"
			  label="姓名"
        fixed="left"
      >
			</el-table-column>
			<el-table-column
			  prop="createTime"
			  label="创建时间"
			  >
			</el-table-column>
			<el-table-column
		    prop = "sex"
		    label = "性别"
		    >
			</el-table-column>
      <el-table-column
        prop = "face"
        label = "政治面貌"
      />
      <el-table-column
        prop = "work"
        label = "工作单位"
      />
      <el-table-column
        prop = "duty"
        label = "职务"
      />
			<el-table-column
			prop="phone"
			label="电话"
			>
			</el-table-column>
			<el-table-column
			prop="email"
			label="邮箱"
			>
			</el-table-column>
      <el-table-column
        prop = "shareNum"
        label = "公司股票代码"
      />
      <el-table-column
        prop = "other"
        label = "其他"
      />
			<el-table-column
			  label="操作"
        fixed="right"
        width="200px"
			>
			<template slot-scope="scope">
        <el-button @click="changes(scope.row.id)" type="text" >编辑信息</el-button>
        <el-button @click="del(scope.row.id)" type="text" >删除人员</el-button>
			</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script>
	export default {
		name:"GoodPeople",
		data(){
			return{
        tableData:[]
			}
		},
		methods:{
			getData(){
        this.$post({
          url : "goodpeople/read"
        }).then(res =>{
          this.tableData = res
        })
      },
      changes(id){
			  this.tableData.forEach((item,index) =>{
			    if(item.id == id){
			      this.$store.commit('setGoodPeople',item)
          }
        })
			  this.$router.push({
          path : "changeGoodPeople?goodpeople_id=" + id
        })
      },
      del(id){
        this.$confirm('此操作将永久删除该捐赠人, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$post({
            url : "goodpeople/delete",
            data : {
              id : id
            }
          }).then(res =>{
            this.getData()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      add(){
			  this.$router.push({
          path : "addGoodPeople"
        })
      }
		},
		components:{

		},
    mounted() {
		  this.getData()
    }
  }
</script>

<style scoped>
  .ss{
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
  }
</style>
